home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Befund3.cpp < prev    next >
C/C++ Source or Header  |  1998-12-22  |  2KB  |  72 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Befund3.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8.  
  9. const String DateiName = "Diagnose.txt";
  10. const String SammelName = "PsychoX.txt";
  11.  
  12. TForm1 *Form1;
  13. TStringList *Diagnose;
  14. TStringList *Psycho;
  15. int Nr;
  16.  
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19.     : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::FormCreate(TObject *Sender)
  24. {
  25.   randomize ();
  26.   Diagnose = new TStringList;
  27.   Psycho = new TStringList;
  28.   try
  29.   {
  30.     Diagnose->LoadFromFile (DateiName);
  31.   }
  32.   catch (...)
  33.   {
  34.     Diagnose->Add ("Keine Sprechstunde");
  35.   }
  36.   ScrollBar1->Min = 0;
  37.   ScrollBar1->Max = Diagnose->Count - 1;
  38. }
  39. //---------------------------------------------------------------------------
  40. void __fastcall TForm1::Button1Click(TObject *Sender)
  41. {
  42.   Panel1->Caption = "";
  43.   Edit1->Text = "";
  44.   Edit1->SetFocus ();
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TForm1::Button2Click(TObject *Sender)
  48. {
  49.   Psycho->Add (Edit1->Text);
  50.   Nr = random (Diagnose->Count);
  51.   Panel1->Caption = Diagnose->Strings[Nr];
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
  55. {
  56.   Panel1->Caption = Diagnose->Strings[ScrollBar1->Position];
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
  60. {
  61.   try
  62.   {
  63.     Psycho->SaveToFile (SammelName);
  64.   }
  65.   catch (...)
  66.   {
  67.     Application->MessageBox
  68.       ("Fehler beim Speichern der Datei!", "Achtung!", 0+48);
  69.   }
  70. }
  71. //---------------------------------------------------------------------------
  72.